public class Executor extends Thread {
	TaskQueue queue;
	Task task;

	public Executor() {
		queue = new TaskQueue();
	}

	public void put(Task request) {
		queue.put(request);
	}

	public Task take() {
		return queue.take();
	}

	@Override
	public void run() {
		while (true) {
			synchronized (Executor.this) {
				task = take();
			}
			synchronized (Executor.this) {
				task.execute();
			}
		}
	}

	public synchronized void undo() {
		if (task != null) {
			task.undo();
		}
		queue.undo();
	}
}
